package cn.ad.param;


import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.HashMap;

public class StrategyQuery extends AbstractPagingSortParam {
	/**
	 * 搜索关键词， 广告住名称或者ID
	 */
	private String search;
	/**
	 * 开始日期
	 */
	@NotNull
	@NotEmpty
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date startDate;
	/**
	 * 结束日期
	 */
	@NotNull
	@NotEmpty
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date endDate;
	/**
	 * 策略状态
	 */
	private Integer status;

	/**
	 * 策略分组ID
	 */
	private Integer strategyGroupId;



	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}


	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	/**
	 * 默认按id排序
	 */
	@Override
	public String getSortby() {
		return StringUtils.isEmpty(super.getSortby()) ? "id" : super.getSortby();
	}

	/**
	 * 默认按降序排序
	 */
	@Override
	public ORDER getOrder() {
		return super.getOrder() == null ? ORDER.desc : super.getOrder();
	}
	
	public HashMap<String, Object> getSearchMap(Integer cid){
		HashMap<String, Object> map = new HashMap<String,Object>(5);
		map.put("campaignId", cid);
		map.put("search", this.search);
		map.put("status", status);
		map.put("sortby", this.getSortby());
		map.put("order", this.getOrder());
		map.put("startTime", this.startDate);
		map.put("endTime", this.endDate);
		map.put("strategyGroupId", this.strategyGroupId);
		return map;
	}

	public Integer getStrategyGroupId() {
		return strategyGroupId;
	}

	public void setStrategyGroupId(Integer strategyGroupId) {
		this.strategyGroupId = strategyGroupId;
	}
}
